package com.bjx.flow.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bjx.flow.domain.entity.FlowInstanceEntity;
import com.bjx.flow.domain.query.FlowInstanceQuery;
import com.bjx.flow.domain.vo.FlowInstanceVO;
import com.bjx.flow.mapper.FlowInstanceMapper;
import com.bjx.flow.service.IFlowInstanceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @desc: 流程实例服务实现
 * @author: liushuai
 * @date: 2022/12/28
 */
@Service("bjxFlowInstanceServiceImpl")
public class FlowInstanceServiceImpl extends ServiceImpl<FlowInstanceMapper, FlowInstanceEntity> implements IFlowInstanceService {
    @Autowired
    private FlowInstanceMapper flowInstanceMapper;

    @Override
    public IPage<FlowInstanceVO> listFlowInstancePage(FlowInstanceQuery flowInstanceQuery) {
        IPage<FlowInstanceVO> iPage = flowInstanceMapper.listFlowInstancePage(flowInstanceQuery.getPage(),flowInstanceQuery);
        return iPage;
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public void insertFlowInstance(FlowInstanceEntity  entity) {
        flowInstanceMapper.insert(entity);
    }

    @Override
    public FlowInstanceEntity selectFlowInstanceByInstanceId(String instanceId) {
        LambdaQueryWrapper<FlowInstanceEntity> wrapper = new LambdaQueryWrapper();
        wrapper.eq(FlowInstanceEntity::getInstanceId,instanceId);
        FlowInstanceEntity flowInstanceEntity = flowInstanceMapper.selectOne(wrapper);
        return flowInstanceEntity;
    }


}
